package com.cjm.algorithm.queue;

import java.util.ArrayDeque;
import java.util.Deque;

public class MyQueue232V2 {
    Deque<Integer> in, out;

    public MyQueue232V2() {
        this.in = new ArrayDeque<>();
        this.out = new ArrayDeque<>();
    }

    public void push(int x) {
        // 一直追加在in的后面
        in.addLast(x);
    }

    public int pop() {
        // 这里的问题， 就是当out为空时， 才往里放数据， 否则就不行了
        if (out.isEmpty()) {
            while (!in.isEmpty()) {
                out.addLast(in.pollLast());
            }
        }
        return out.pollLast();
    }

    public int peek() {
        if (out.isEmpty()) {
            while (!in.isEmpty()) {
                out.addLast(in.pollLast());
            }
        }
        return out.peekLast();
    }

    public boolean empty() {
        return out.isEmpty() && in.isEmpty();
    }
}
